<?php
class Application_Model_Country extends Zend_Db_Table_Abstract
{
    protected $_name = 'country';
    protected $_primary = 'country_id';
   
    public function getCountryArea()
    {
        $select = $this->getAdapter()->select();
        $select->from('country_area');
        $select->limit(10);
        $result = $this->getAdapter()->fetchAll($select);
        
        return $result;
    }
    
    public function getCountries()
    {
        $select = $this->getAdapter()->select();
        $select->from('country');
        $select->order("rand()");
        $select->limit(35);
        $result = $this->getAdapter()->fetchAll($select);
        
        return $result;
    }
    
    public function getAllCountries()
    {
        $select = $this->getAdapter()->select();
        $select->from('country');
        $select->order('name ASC');
        $result = $this->getAdapter()->fetchAll($select);
        
        return $result;
    }
    
    public function getCountrySort($sort)
    {
        $select = $this->getAdapter()->select();
        $select->from('country');
        $select->where('sort=?', $sort);
        $result = $this->getAdapter()->fetchAll($select);
        
        return $result;
    }
    
    public function getCountryName($code)
    {
        $select = $this->getAdapter()->select();
        $select->from('country');
        $select->where('code=?', $code);
        $result = $this->getAdapter()->fetchRow($select);
        
        return $result;
    }
    
    public function getCountryWithArea($areaId)
    {
        $select = $this->getAdapter()->select();
        $select->from('country');
        $select->where('country_area_id=?', $areaId);
        $select->limit(3);
        $result = $this->getAdapter()->fetchAll($select);
        
        return $result;
    }
}